import { defineStore } from 'pinia';
import router from '@/router';

export const useTeacherStore = defineStore('teacherId', {
    state: () => ({
        // 用于判断是哪个老师
        roleNums: [],
        //
        restrictState: 0,
        // 所带班级
        className: '',
        teacherName: '',
        teacherId: ''
    }),
    actions: {
        /**
         * 获取用户信息
         */
        async login({ roleNums, userName, restrictState, userNum, className }) {
            localStorage.setItem('userType', 'teacher');
            this.roleNums = roleNums;
            this.teacherName = userName;
            if (!this.getRestrictState()) {
                this.restrictState = restrictState;
                this.setRestrictState(restrictState);
            }
            this.teacherId = userNum;
            this.className = className;
        },
        logout() {
            this.removeRestrictState();
            this.$reset();
        },
        getRestrictState() {
            localStorage.getItem('restrictState');
        },
        setRestrictState(value) {
            this.restrictState = value;
            localStorage.setItem('restrictState', value);
        },
        removeRestrictState() {
            localStorage.removeItem('restrictState');
        }
    }
});
